<template>
  <el-card shadow="never" class="aui-card--fill">
    <div class="mod-pet__petreport}">
      <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
        <el-form-item>
          <el-input v-model="dataForm.id" placeholder="id" clearable></el-input>
        </el-form-item>
        <el-form-item>
          <el-button @click="getDataList()">{{ $t('query') }}</el-button>
        </el-form-item>
      </el-form>
      <el-table v-loading="dataListLoading" :data="dataList" border @selection-change="dataListSelectionChangeHandle" style="width: 100%;">
        <el-table-column type="selection" header-align="center" align="center" width="50"></el-table-column>
        <el-table-column prop="reportedUserName" label="被举报人姓名" header-align="center" align="center"></el-table-column>
        <el-table-column prop="imageUrl" label="照片" header-align="center" align="center">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.imageUrlSize === 0" size="small" type="danger">暂无图片</el-tag>
            <el-image v-else style="width: 80px; height: 80px" :src="scope.row.imageUrlList[0]"
              :preview-src-list="scope.row.imageUrlList"></el-image>
          </template>
        </el-table-column>
        <el-table-column prop="reportType" label="举报类型" header-align="center" align="center">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.reportType === 0" size="small" type="danger">淫秽信息</el-tag>
            <el-tag v-if="scope.row.reportType === 1" size="small" type="danger">诈骗信息</el-tag>
            <el-tag v-if="scope.row.reportType === 2" size="small" type="danger">广告信息</el-tag>
            <el-tag v-if="scope.row.reportType === 3" size="small" type="danger">其他</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="reportContent" label="举报内容" header-align="center" align="center"></el-table-column>
        <el-table-column prop="status" label="审核状态" header-align="center" align="center">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.status === 0" size="small" type="warning">待审核</el-tag>
            <el-tag v-if="scope.row.status === 1" size="small" type="success">审核通过</el-tag>
            <el-tag v-if="scope.row.status === 2" size="small" type="danger">未通过</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="审核" fixed="right" header-align="center" align="center" width="150">
          <template slot-scope="scope">
            <el-button type="text" size="small" @click="examine(scope.row.id, 1)">通过</el-button>
            <el-button type="text" size="small" @click="examine(scope.row.id, 2)">未通过</el-button>
          </template>
        </el-table-column>
        <el-table-column prop="creatorName" label="举报人" header-align="center" align="center"></el-table-column>
        <el-table-column prop="createDate" label="创建时间" header-align="center" align="center"></el-table-column>
      </el-table>
      <el-pagination
        :current-page="page"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="limit"
        :total="total"
        layout="total, sizes, prev, pager, next, jumper"
        @size-change="pageSizeChangeHandle"
        @current-change="pageCurrentChangeHandle">
      </el-pagination>
      <!-- 弹窗, 新增 / 修改 -->
      <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
    </div>
  </el-card>
</template>

<script>
import mixinViewModule from '@/mixins/view-module'
import AddOrUpdate from './petreport-add-or-update'
export default {
  mixins: [mixinViewModule],
  data () {
    return {
      mixinViewModuleOptions: {
        getDataListURL: '/pet/petreport/page',
        getDataListIsPage: true,
        deleteURL: '/pet/petreport',
        deleteIsBatch: true
      },
      dataForm: {
        id: ''
      }
    }
  },
  components: {
    AddOrUpdate
  },
  methods: {
    // 审核接口
    examine(id, status) {
      this.$http
        .put("/pet/petreport/examine", {
          id: id,
          status: status
        })
        .then(({ data: res }) => {
          if (res.code == 0) {
            this.$message({
              message: "审核提交成功！",
              type: "success",
            });
            this.query();
          } else {
            this.$message.error("审核提交失败！");
          }
        });
    }
  }
}
</script>
